<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<link href="${contextPath}/resources/plugins/select2-4.0/select2.css" rel="stylesheet" />
<script src="${contextPath}/resources/plugins/select2-4.0/select2.full.min.js" type="text/javascript"></script>
<script src="${contextPath}/resources/plugins/select2-4.0/i18n/zh-CN.js" type="text/javascript"></script>
<script src="${contextPath}/resources/plugins/select2-4.0/makeSelect2.js" type="text/javascript"></script>
<script src="${contextPath}/resources/plugins/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<link href="${contextPath}/resources/plugins/select2-4.0/select2.css" rel="stylesheet" />
<script src="${contextPath}/resources/plugins/fullcalendar/lib/moment.min.js" type="text/javascript"></script>
<link href="${contextPath}/resources/plugins/fullcalendar/fullcalendar.min.css" rel="stylesheet" />
<script type="text/javascript"  src="${contextPath}/resources/common/js/jquery.validate.js"></script>
<script type="text/javascript"  src="${contextPath}/resources/plugins/fullcalendar/fullcalendar.min.js"></script>
<script type="text/javascript"  src="${contextPath}/resources/plugins/fullcalendar/locale/zh-cn.js"></script>
<table class="${tableclass}" style="width: 100%">
	<tr>
		<th><strong class="am-text-primary am-text-lg">首页</strong> / 项目管理 / 日志管理</th>
	</tr>
</table>
<form action="<ls:url address='/admin/dailylog/query'/>" id="form1" method="post">
    <input type="hidden" id="curPageNO" name="curPageNO" value="${curPageNO}">
	<table class="${tableclass}" style="width: 100%">
		<tbody>
			<tr>
				<td>
					<div align="left" style="padding: 3px">
					   
					   <input type="hidden" value="2" id="dailyLogEnum" name="dailyLogEnum"/> 
							<select name="userName" id="userName" style="width: 120px">
								<c:if test="${not empty dailyLogQueryDto.userName}">
									<option value="${dailyLogQueryDto.userName}">${userRealName}</option>
								</c:if>
							</select> 
						时间
						<input type="button" value="今天" id="todayLog" class="logbutton"/> 
						<input type="button" value="昨天" id="yesterdayLog" class="logbutton"/> 
						<input type="button" value="本周" id="thisWeekLog"  class="logbutton criteria-btn"/> 
						<input type="button" value="上周" id="lastWeekLog" class="logbutton"/> 
						<input type="button" value="本月" id="thisMonthLog" class="logbutton"/> 
						<input type="button" value="上月" id="lastMonthLog" class="logbutton"/> 
						<input type="button" value="所有" id="allLog" class="logbutton"/> 
						<!-- 
						自定义 从: 
						<input readonly="readonly" name="startDate" id="startDate" class="Wdate" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',onpicked:function(){endDate.focus();},maxDate:'#F{$dp.$D(\'endDate\')}'})" value='<fmt:formatDate value="${taskQueryDto.startDate}" pattern="yyyy-MM-dd"/>' /> 
						到: 
						<input readonly="readonly" name="endDate" id="endDate" class="Wdate" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startDate\')}'})" value='<fmt:formatDate value="${taskQueryDto.endDate}" pattern="yyyy-MM-dd"/>' /> 
						<input type="submit" value="搜索" />
						 -->
						<input type="button" value="创建日志" class="criteria-btn" onclick="javascript:taskEstimate('${date}')" />
						<font color="red">可以在周数上点击可以直接新建对应周的周报.</font>
					</div>
				</td>
			</tr>
		</tbody>
	</table>
</form>
<!-- HTML 代码 -->
<div id='calendarContent' style="margin: 20px;"></div>
<script language="JavaScript" type="text/javascript">
        
			  $(document).ready(function() {
					//三级联动
			     	$("select.combox").initSelect();

			     	$("#userName").change(function () {
			     	   
                        var type = $("#dailyLogEnum").val();
                        if(type == 2){//本周模式
                            sendData();
                        }else{
                            sendDataForLogList();
                        }

                    });
					//查找所有/userList， 查找下级/userListForMyColleague
			     	makeSelect2(contextPath + "/admin/adminUser/userList","#userName","成员","value","key");
			     	sendData();//本周模式
				    $("#form1").validate({
						submitHandler:function(form){
							sendData();//点击提交按钮触发提交数据
					    }
					  });
				    
				    $("#todayLog").click(function(){
				    	$(".logbutton").each(function(){
				    	$(this).removeClass("criteria-btn");
				    	});
				    	var $this = $(this);
				    	$this.addClass("criteria-btn");
				    	$("#dailyLogEnum").val(0);
				    	sendDataForLogList();
				    });
				    
				    $("#yesterdayLog").click(function(){
				    	$(".logbutton").each(function(){
				    		$(this).removeClass("criteria-btn");
				    	});
				    	var $this = $(this);
				    	$this.addClass("criteria-btn");
				    	$("#dailyLogEnum").val(1);
				    	sendDataForLogList();
				    });
				    
				    $("#thisWeekLog").click(function(){
				    	$(".logbutton").each(function(){
				    		$(this).removeClass("criteria-btn");
				    	});
				    	var $this = $(this);
				    	$this.addClass("criteria-btn");
				    	$("#dailyLogEnum").val(2);
				    	sendData();
				    });
				    
				    $("#lastWeekLog").click(function(){
				    	$(".logbutton").each(function(){
				    		$(this).removeClass("criteria-btn");
				    	});
				    	var $this = $(this);
				    	$this.addClass("criteria-btn");
				    	$("#dailyLogEnum").val(3);
				    	sendDataForLogList();
				    });
				    
				    $("#thisMonthLog").click(function(){
				    	$(".logbutton").each(function(){
				    		$(this).removeClass("criteria-btn");
				    	});
				    	var $this = $(this);
				    	$this.addClass("criteria-btn");
				    	$("#dailyLogEnum").val(4);
				    	sendDataForLogList();
				    });
				    
				    $("#lastMonthLog").click(function(){
				    	$(".logbutton").each(function(){
				    		$(this).removeClass("criteria-btn");
				    	});
				    	var $this = $(this);
				    	$this.addClass("criteria-btn");
				    	$("#dailyLogEnum").val(5);
				    	sendDataForLogList();
				    });
				    
				    $("#allLog").click(function(){
				    	$(".logbutton").each(function(){
				    		$(this).removeClass("criteria-btn");
				    	});
				    	var $this = $(this);
				    	$this.addClass("criteria-btn");
				    	$("#dailyLogEnum").val(6);
				    	sendDataForLogList();
				    });
				    
			  });
        
			  

		function sendData(){
					var formData = $("#form1").serialize();
				     $.ajax({
				    		url:"${contextPath}/admin/dailylog/queryContent", 
				    		type:'post', 
				    		data:formData,
				    		async : true, //默认为true 异步   
				    		error: function(jqXHR, textStatus, errorThrown) {
				    		 //  alert("系统异常" + " jqXHR= " + jqXHR + ", textStatus = " + textStatus + ",errorThrown =  " + errorThrown);
				    		},
				    		success:function(result){
				    		   $("#calendarContent").html(result);
				    		}
				    	});
		 }
			  
		function sendDataForLogList(){
					var formData = $("#form1").serialize();
				     $.ajax({
				    		url:"${contextPath}/admin/dailylog/queryLogList", 
				    		type:'post', 
				    		data:formData,
				    		async : true, //默认为true 异步   
				    		error: function(jqXHR, textStatus, errorThrown) {
				    		 //  alert("系统异常" + " jqXHR= " + jqXHR + ", textStatus = " + textStatus + ",errorThrown =  " + errorThrown);
				    		},
				    		success:function(result){
				    		   $("#calendarContent").html(result);
				    		}
				    	});
		 }

		 //日期控件移动内容
		function moveTaskEstimate(id, date){
				  $.ajax({
					  url:"${contextPath}/admin/dailylog/moveTaskEstimate",
					  type:'post',
					  data:{"id": id, "date": date},
					  async : true, //默认为true 异步
					  dataType : 'json',
					  error: function(jqXHR, textStatus, errorThrown) {
						  //  alert("系统异常" + " jqXHR= " + jqXHR + ", textStatus = " + textStatus + ",errorThrown =  " + errorThrown);
					  },
					  success:function(result){
						 if(result != "success"){
						 	alert("不可以移动该数据");
						 }
					  }
				  });
			  }
				
		 //填写工时
		function taskEstimate(date){
			    		var userName = $("#userName").val();
			    		if(userName == 'undefined'){
			    			userName = '';
			    		}
			   		    var page = contextPath + "/admin/task/taskEstimateByDay/" + date + "?userName=" + userName;
			    		layer.open({
				    		  type: 2,
				    		  id: "taskEstimate",
				    		  title: " 日期:" + date,
				    		  area: ['1150px','600px'],
				    		  content: [page,'no'] //iframe的url，no代表不显示滚动条
				    });
			}	
			   	 
			   	 
		//填写周报
		function createWeeklyLog(date, userName){
				var page = contextPath + "/admin/weekLog/load?date=" + date + "&userName=" + userName;
				layer.open({
		   		  type: 2,
		   		  id: "createWeeklyLog",
		   		  title: " 日期:" + date,
		   		  area: ['800px','600px'],
		   		  content: [page,'no'] //iframe的url，no代表不显示滚动条
		   });
		}	
			   	 
				
		</script>
